package com.zhitong.ztblog.mappers;

import com.zhitong.ztblog.entity.Comment;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestBody;

@Mapper
public interface CommentMapper {

    @Results(id = "commentMap",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "bid",column = "bid"),
            @Result(property = "blog",column = "bid",one = @One(select = "com.zhitong.ztblog.mappers.BlogMapper.findById")),
            @Result(property = "nickName",column = "nickName"),
            @Result(property = "content",column = "content"),
            @Result(property = "createTime",column = "createTime"),
    })
    @Select("select * from comment where bid =#{bid}  order by createTime desc")
    public Comment[] findByBid(int bid);

    @Insert("insert into Comment values(null,#{bid},#{nickName},#{content},#{createTime})")
    public void insertComment(Comment comment);

    @ResultMap("commentMap")
    @Select("select * from comment limit #{currentPage},#{pageSize} ")
    public Comment[] findCommentByPage(int currentPage,int pageSize);

    @Select("select count(*) from comment")
    public int findCount();

    @Delete("delete from comment where id = #{id}")
    public void delCommentById(int id);
}
